#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * DNS Key Record Structure
 *      Represents a DNS key (KEY) record.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Net;

namespace Adaptive
{
	namespace Network
	{
		namespace Dns
		{
			/// <summary>
			/// Represents a DNS key (KEY) record.
			/// </summary>
			public value struct DnsKeyRecord
			{
			internal:
				/// <summary>
				/// Initializes a new instance of the class from the unmanaged record.
				/// </summary>
				/// <param name="record"> A pointer to a DNS_RECORD structure whose contents are to be copied.</param>
				DnsKeyRecord(DNS_RECORD* record)
				{
					int count = 0;
					int length = 0;

					if (record == NULL)
					{
						Flags = 0;
						Protocol = 0;
						Algorithm = 0;
						KeyData = nullptr;
					}
					else
					{
						Flags = record->Data.KEY.wFlags;
						Protocol = record->Data.KEY.chProtocol;
						Algorithm = record->Data.KEY.chAlgorithm;
						length = strlen((const char*)record->Data.KEY.Key);
						KeyData = gcnew array<Byte>( length );
						for(count = 0; count < length; count++)
							KeyData[count] = (Byte)record->Data.KEY.Key[count];
					}
				}
			public:
				/// <summary>
				///	Flags used to specify mapping.
				/// </summary>
				/// <value>
				/// Value of flags.
				/// </value>
				short	Flags;
				/// <summary>
				///	Protocol for which the key specified in the resource record can be used.
				/// </summary>
				/// <value>
				/// The assigned values are shown in the following table:
				///
				///	Value	Meaning 
				/// 1		TLS
				/// 2		E-Mail
				/// 3		DNSSEC
				/// 4		IPSec
				/// 255		All protocols
				/// </value>
				Byte	Protocol;
				/// <summary>
				///	Algorithm used with the key specified in the resource record.
				/// </summary>
				/// <value>
				/// The assigned values are shown in the following table:
				///
				///	Value	Meaning 
				/// 1		RSA/MD5 (RFC 2537)
				/// 2		Diffie-Hellman (RFC 2539)
				/// 3		DSA (RFC 2536)
				/// 4		Elliptic curve cryptography.
				/// </value>
				Byte	Algorithm;
				/// <summary>
				/// Public key.
				/// </summary>
				/// <value>
				/// Represented in base 64 as described in Appendix A of RFC 2535.
				/// </value>
				array<Byte>^	KeyData;

			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static DnsKeyRecord()
				{
				}

			};
		}
	}
}
